import { request } from '@/plugins/request'


// 用户登录
export const login = data => {
  return request({
    method: 'POST',
    url: '/api/users/login',
    data
  })
}

// 用户注册
export const register = data => {
  return request({
    method: 'POST',
    url: '/api/users',
    data
  })
}


// 获取文章标签列表
export const getTags = () => {
    return request({
      method: 'GET',
      url: '/api/tags'
    })
  }
  


// 获取公共文章列表
export const getArticles = params => {
    return request({
      method: 'GET',
      url: '/api/articles',
      params
    })
  }
  
  // 获取公共文章列表
  export const getYourFeedArticles = params => {
    return request({
      method: 'GET',
      url: '/api/articles/feed',
      params,
      // headers: {
      //   // 添加用户身份，数据格式：Token空格Token数据
      //   Authorization: `Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDgxMTYsInVzZXJuYW1lIjoibHB6OTk5IiwiZXhwIjoxNTk3NzQxNTA4fQ.2yO8Fss4hYnvsIN2UYHsutQ1hmYqSSAA-UrIRnP4DOY`
      // }
    })
  }
  
  // 添加点赞
  export const addFavorite = slug => {
    return request({
      method: 'POST',
      url: `/api/articles/${slug}/favorite`
    })
  }
  
  // 取消点赞
  export const deleteFavorite = slug => {
    return request({
      method: 'DELETE',
      url: `/api/articles/${slug}/favorite`
    })
  }
  
  // 获取文章详情
  export const getArticle = slug => {
    return request({
      method: 'GET',
      url: `/api/articles/${slug}`
    })
  }
  
  // 获取文章评论
  export const getComments = slug => {
    return request({
      method: 'GET',
      url: `/api/articles/${slug}/comments`
    })
  }
  
